<?php
session_start();
if (empty($_SESSION['username'])) {
    echo '<script type="text/javascript">window.location.href="index.php";</script>';
} else {
    $now = time();
    if ($now > $_SESSION['expire']) {
        session_destroy();
        echo '<script type="text/javascript">var r=confirm("Session expire (30 mins)!"); if(r==true){window.location.href="index.php";}else{window.location.href="index.php";}</script>';
    } else {
        
    }
}
?>
<!DOCTYPE html>
<html lang="en">

    <head>

        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">

        <title>SwissMooh - Admin Page</title>

        <!-- Bootstrap Core CSS -->
        <link href="assets/css/bootstrap.min.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="assets/css/sb-admin.css" rel="stylesheet">

        <!-- Morris Charts CSS -->
        <link href="assets/css/plugins/morris.css" rel="stylesheet">
        <!-- Custom Fonts -->
        <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
        <link href="assets/css/jquery-ui.min.css" rel="stylesheet" type="text/css">

        <style>            
            label, input { display:block; }
            input.text { margin-bottom:12px; width:95%; padding: .4em; }
            fieldset { padding:0; border:0; margin-top:25px; }
            h1 { font-size: 1.2em; margin: .6em 0; }
            div#users-contain { width: 350px; margin: 20px 0; }
            div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
            div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
            .ui-dialog .ui-state-error { padding: .3em; }
            .validateTips { border: 1px solid transparent; padding: 0.3em; }
            .hide_add_menu {visibility: hidden;'}
            </style>
            <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
            <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
            <!--[if lt IE 9]>
                <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
                <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
            <![endif]-->

        </head>

        <body>

            <div id="wrapper">

                <!-- Navigation -->
                <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="welcome_page.php">SwissMooh Admin</a>
                    </div>
                    <!-- Top Menu Items -->
                    <ul class="nav navbar-right top-nav">                                        
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> <?= $_SESSION['username'] ?><b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="change_password.php">Change Password</a>
                                </li>
                                <li class="divider"></li>
                                <li>
                                    <a href="#" id="logout_click"><i class="fa fa-fw fa-power-off"></i> Log Out</a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                    <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
                    <div class="collapse navbar-collapse navbar-ex1-collapse">
                        <ul class="nav navbar-nav side-nav">
                            <li class="active">
                                <a href="menu_main_page.php"><i class="fa fa-fw fa-bar-chart-o"></i> Manage Menu List</a>
                            </li>
                            <li>
                                <a href="manage_carousel_page.php"><i class="fa fa-fw fa-edit"></i> Manage Carousel Content</a>
                            </li>
                            <li>
                                <a href="contact_main_page.php"><i class="fa fa-fw fa-edit"></i> Manage Contact Content</a>
                            </li>
                        </ul>
                    </div>
                    <!-- /.navbar-collapse -->
                </nav>

                <div id="page-wrapper">

                    <div class="container-fluid">

                        <!-- Page Heading -->
                        <div class="row">
                            <div class="col-lg-12">
                                <h1 class="page-header">
                                    Menu <small>Manage Menu Page</small>
                                </h1>
                                <ol class="breadcrumb">
                                    <li class="active">
                                        <i class="fa fa-dashboard"></i> Manage Menu
                                    </li>
                                </ol>
                            </div>
                        </div>
                        <!-- /.row -->
                        <div class="row">
                            <div class="col-lg-12" id="content_manage">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <div class="pull-right">
                                            <input type="button" class="btn btn-xs btn-primary" id="add_desc_content" value="Add Content"/>
                                            <input type="button" class="btn btn-xs btn-danger" id="cancelAddContent" value="Cancel"/>
                                        </div>
                                        <h3 class="panel-title">Page Content Management</h3>

                                    </div>
                                    <div class="panel-body">
                                        <div id="load_desc_content"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-4">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <div class="pull-right" style="cursor: pointer" id="add_menu_level1"><b>Add</b></div>
                                        <h3 class="panel-title">Main Menu</h3>

                                    </div>
                                    <div class="panel-body">
                                        <div class="list-group" id="main_menu_list">

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <div class="pull-right" style="cursor: pointer" id="add_menu_level2"><b>Add</b></div>
                                        <h3 class="panel-title">Menu Level 1</h3>
                                    </div>
                                    <div class="panel-body" id="menu_level_one">
                                        Please select Main menu..
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <div class="pull-right" style="cursor: pointer" id="add_menu_level3"><b>Add</b></div>
                                        <h3 class="panel-title">Menu Level 2</h3>
                                    </div>
                                    <div class="panel-body" id="menu_level_two">
                                        Please select menu level 1..
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.row -->

                        <div class="row" style="height: 400px;"></div>
                    </div>
                    <!-- /.container-fluid -->

                </div>
                <!-- /#page-wrapper -->
                <input type="hidden" id="mainMenuID"/>

                <input type="hidden" id="mainMenuIDLevelOne"/>
                <input type="hidden" id="refMenuIDLevelOne"/>

                <input type="hidden" id="mainMenuIDLevelTwo"/>
                <input type="hidden" id="refMenuIDLevelTwo"/>
            </div>
            <!-- /#wrapper -->
            <div id="dialog-form" title="Create Main Menu">
                <form>
                    <fieldset>
                        <label for="name">Menu Name</label>
                        <input type="text" name="menu_name" id="menu_name" class="text ui-widget-content ui-corner-all">

                        <!-- Allow form submission with keyboard without duplicating the dialog button -->
                        <input type="button" id="click_create_main_menu" style="position:absolute;" value="Create"/>
                    </fieldset>
                </form>
            </div>
            <div id="dialog-form_levelOne" title="Create Menu Level one">
                <form>
                    <fieldset>
                        <label for="name">Menu Name</label>
                        <input type="text" name="menu_name1" id="menu_name1" class="text ui-widget-content ui-corner-all">
                        <!-- Allow form submission with keyboard without duplicating the dialog button -->
                        <input type="button" id="click_create_main_menu_level1" style="position:absolute;" value="Create"/>
                    </fieldset>
                </form>
            </div>
            <div id="dialog-form_levelTwo" title="Create Menu Level Two">
                <form>
                    <fieldset>
                        <label for="name">Menu Name</label>
                        <input type="text" name="menu_name2" id="menu_name2" class="text ui-widget-content ui-corner-all">
                        <!-- Allow form submission with keyboard without duplicating the dialog button -->
                        <input type="button" id="click_create_main_menu_level2" style="position:absolute;" value="Create"/>
                    </fieldset>
                </form>
            </div>
            <div id="dialog_manage_menu_content" title="Create/Update Content">
                <div id="load_dialog_content"></div>
            </div>
            <input type="hidden" id="menuIDSelect"/>
            <!-- jQuery -->
            <script src="assets/js/jquery.js"></script>
            <script src="assets/js/jquery-ui.min.js"></script>
            <!-- Bootstrap Core JavaScript -->
            <script src="assets/js/bootstrap.min.js"></script>
            <script src="assets/js/jquery.blockUI.js"></script>
            <script src="assets/js/SwissMoohScript.js"></script>
            <script type="text/javascript">
                $("#content_manage").hide();
                var state = "Create";
                var stateLevelOne = "Create";
                var stateLevelTwo = "Create";

                $(function () {
                    $("#add_menu_level2").addClass("hide_add_menu");
                    $("#add_menu_level3").addClass("hide_add_menu");
                    $("#add_desc_content").click(function () {
                        updateSessionTimeOutCallBack();
                        var menuIDSelect = $("#menuIDSelect").val();
                        window.location = "main_description_page.php?menuIDSelect=" + menuIDSelect;
                    });
                    $("#cancelAddContent").click(function () {
                        updateSessionTimeOutCallBack();
                        $("#content_manage").hide("fast");
                    });
                    $.ajax({
                        url: 'model/com.swiss.mooh.controller/CreateMenuController.php',
                        type: 'POST',
                        beforeSend: function (xhr) {
                            $.blockUI({css: {
                                    border: 'none',
                                    padding: '15px',
                                    backgroundColor: '#fff',
                                    '-webkit-border-radius': '10px',
                                    '-moz-border-radius': '10px',
                                    opacity: .5,
                                    color: '#fff'
                                }, message: '<img src="assets/images/gears.gif"/>'});
                        },
                        data: {'type': 99},
                        success: function (data, textStatus, jqXHR) {
                            if (data == null || data == "") {
                                $("#main_menu_list").html("No data found");
                                setTimeout($.unblockUI, 100);
                            } else {
                                $("#main_menu_list").html(data);
                                setTimeout($.unblockUI, 100);
                            }

                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            alert(errorThrown);
                        }
                    });
                    var dialog = $("#dialog-form").dialog({
                        autoOpen: false,
                        height: 200,
                        width: 350,
                        modal: true
                    });

                    var dialog1 = $("#dialog-form_levelOne").dialog({
                        autoOpen: false,
                        height: 200,
                        width: 350,
                        modal: true
                    });
                    var dialog2 = $("#dialog-form_levelTwo").dialog({
                        autoOpen: false,
                        height: 200,
                        width: 350,
                        modal: true
                    });
                    $("#add_menu_level1").button().on("click", function () {
                        updateSessionTimeOutCallBack();
                        state = "Create";
                        $("#menu_name").val("");
                        dialog.dialog("open");
                    });
                    $("#add_menu_level2").button().on("click", function () {
                        updateSessionTimeOutCallBack();
                        stateLevelOne = "Create";
                        $("#menu_name1").val("");
                        dialog1.dialog("open");
                    });
                    $("#add_menu_level3").button().on("click", function () {
                        updateSessionTimeOutCallBack();
                        stateLevelTwo = "Create";
                        $("#menu_name2").val("");
                        dialog2.dialog("open");
                    });
                    $("#click_create_main_menu").click(function () {
                        updateSessionTimeOutCallBack();
                        var menuName = $("#menu_name").val();
                        if (menuName == "") {
                            alert("Please enter menu name");
                        } else {
                            if (state == "Create") {
                                addingMenuLevelOne(dialog, menuName);
                            } else {
                                var menuID = $("#mainMenuID").val();
                                updateMainMenu(menuID, menuName);
                                dialog.dialog("close");
                            }
                        }

                    });
                    $("#click_create_main_menu_level2").click(function () {
                        updateSessionTimeOutCallBack();
                        var menuName = $("#menu_name2").val();
                        var ref_id = $("#refMenuIDLevelTwo").val();
                        if (menuName == "") {
                            alert("Please enter menu name");
                        } else {
                            if (stateLevelTwo == "Create") {
                                addMenuLevelThree(dialog2, menuName, ref_id);
                            } else {
                                var mainMenuID = $("#mainMenuIDLevelTwo").val();
                                var menuName = $("#menu_name2").val();
                                var refMenuID = $("#refMenuIDLevelTwo").val();
                                updateMenuLevelTwo(mainMenuID, menuName, refMenuID);
                                dialog2.dialog("close");
                            }

                        }
                    });
                    $("#click_create_main_menu_level1").click(function () {
                        updateSessionTimeOutCallBack();
                        if (menuName == "") {
                            alert("Please enter menu name");
                        } else {
                            if (stateLevelOne == "Create") {
                                var menuName = $("#menu_name1").val();
                                var mainMenuID = $("#mainMenuID").val();
                                addingMenuLevelTwo(dialog1, menuName, mainMenuID);
                            } else {
                                var mainMenuID = $("#mainMenuIDLevelOne").val();
                                var menuName = $("#menu_name1").val();
                                var refMenuID = $("#refMenuIDLevelOne").val();
                                updateMainMenuLevelOne(mainMenuID, menuName, refMenuID);
                                dialog1.dialog("close");
                            }
                        }
                    });
                });
            </script>
        </body>

    </html>
